package com.example.productservice.config;

import com.example.productservice.model.Product;
import com.example.productservice.repository.ProductRepository;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.math.BigDecimal;

@Configuration
public class DataInitializer {

    @Bean
    public CommandLineRunner initData(ProductRepository repository) {
        return args -> {
            // 创建并保存几个示例产品
            Product product1 = new Product();
            product1.setName("智能手机");
            product1.setDescription("高性能智能手机，搭载最新处理器");
            product1.setPrice(new BigDecimal("99.99"));
            product1.setStock(100);
            
            Product product2 = new Product();
            product2.setName("笔记本电脑");
            product2.setDescription("轻薄笔记本电脑，办公娱乐两相宜");
            product2.setPrice(new BigDecimal("299.99"));
            product2.setStock(50);
            
            Product product3 = new Product();
            product3.setName("无线耳机");
            product3.setDescription("降噪无线耳机，长续航");
            product3.setPrice(new BigDecimal("29.99"));
            product3.setStock(200);
            
            repository.save(product1);
            repository.save(product2);
            repository.save(product3);
            
            System.out.println("产品服务 - 初始化数据完成");
        };
    }
} 